﻿using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class Remover:MonoBehaviour {


    public GameObject splash;

    private void OnTriggerEnter2D(Collider2D col) {



        if (col.gameObject.tag == "Player")
        {
            Debug.Log("Player");

            GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraFollow>().enabled = false;

            Instantiate(splash,col.transform.position,transform.rotation);

            Destroy(col.gameObject);

            StartCoroutine("ReloadGame");
        }
        else {

            Instantiate(splash,col.transform.position,transform.rotation);

            Destroy(col.gameObject);
        }

    }


    IEnumerator ReloadGame() {
        // ... pause briefly
        yield return new WaitForSeconds(2);
        // ... and then reload the level.
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex,LoadSceneMode.Single);
    }

}
